Refactored Database*::getLag(): moved the default implementation to MySQL, replaced...
authorMax Semenik <maxsem@users.mediawiki.org>
Fri, 2 Jul 2010 13:17:28 +0000 (13:17 +0000)
committerMax Semenik <maxsem@users.mediawiki.org>
Fri, 2 Jul 2010 13:17:28 +0000 (13:17 +0000)
includes/db/Database.php
includes/db/DatabaseIbm_db2.php
includes/db/DatabaseMysql.php
includes/db/DatabaseOracle.php
includes/db/DatabasePostgres.php
includes/db/DatabaseSqlite.php

index d38b6c3..c3ef663 100644 (file)
@@ -2098,41 +2098,11 @@ abstract class DatabaseBase {
 
        /**
         * Get slave lag.
-        * At the moment, this will only work if the DB user has the PROCESS privilege
+        * Currently supported only by MySQL
+        * @return Database replication lag in seconds
         */
        function getLag() {
-               if ( !is_null( $this->mFakeSlaveLag ) ) {
-                       wfDebug( "getLag: fake slave lagged {$this->mFakeSlaveLag} seconds\n" );
-                       return $this->mFakeSlaveLag;
-               }
-               $res = $this->query( 'SHOW PROCESSLIST', __METHOD__ );
-               # Find slave SQL thread
-               while ( $row = $this->fetchObject( $res ) ) {
-                       /* This should work for most situations - when default db
-                        * for thread is not specified, it had no events executed,
-                        * and therefore it doesn't know yet how lagged it is.
-                        *
-                        * Relay log I/O thread does not select databases.
-                        */
-                       if ( $row->User == 'system user' &&
-                               $row->State != 'Waiting for master to send event' &&
-                               $row->State != 'Connecting to master' &&
-                               $row->State != 'Queueing master event to the relay log' &&
-                               $row->State != 'Waiting for master update' &&
-                               $row->State != 'Requesting binlog dump' &&
-                               $row->State != 'Waiting to reconnect after a failed master event read' &&
-                               $row->State != 'Reconnecting after a failed master event read' &&
-                               $row->State != 'Registering slave on master'
-                               ) {
-                               # This is it, return the time (except -ve)
-                               if ( $row->Time > 0x7fffffff ) {
-                                       return false;
-                               } else {
-                                       return $row->Time;
-                               }
-                       }
-               }
-               return false;
+               return $this->mFakeSlaveLag;            
        }
 
        /**
index 4a10bd6..024990c 100644 (file)
@@ -1501,16 +1501,6 @@ EOF;
         * @deprecated
         */
        public function getStatus( $which="%" ) { $this->installPrint('Not implemented for DB2: getStatus()'); return ''; }
-       /**
-        * Not implemented
-        * TODO
-        * @return bool true
-        */
-       /**
-        * Not implemented
-        * @deprecated
-        */
-       public function setFakeSlaveLag( $lag ) { $this->installPrint('Not implemented for DB2: setFakeSlaveLag()'); }
        /**
         * Not implemented
         * @deprecated
index 58809f1..dcdfa2d 100644 (file)
@@ -304,6 +304,46 @@ class DatabaseMysql extends DatabaseBase {
                return true;
        }
 
+       /**
+        * Returns slave lag.
+        * At the moment, this will only work if the DB user has the PROCESS privilege
+        * @result int
+        */
+       function getLag() {
+               if ( !is_null( $this->mFakeSlaveLag ) ) {
+                       wfDebug( "getLag: fake slave lagged {$this->mFakeSlaveLag} seconds\n" );
+                       return $this->mFakeSlaveLag;
+               }
+               $res = $this->query( 'SHOW PROCESSLIST', __METHOD__ );
+               # Find slave SQL thread
+               while ( $row = $this->fetchObject( $res ) ) {
+                       /* This should work for most situations - when default db
+                        * for thread is not specified, it had no events executed,
+                        * and therefore it doesn't know yet how lagged it is.
+                        *
+                        * Relay log I/O thread does not select databases.
+                        */
+                       if ( $row->User == 'system user' &&
+                               $row->State != 'Waiting for master to send event' &&
+                               $row->State != 'Connecting to master' &&
+                               $row->State != 'Queueing master event to the relay log' &&
+                               $row->State != 'Waiting for master update' &&
+                               $row->State != 'Requesting binlog dump' &&
+                               $row->State != 'Waiting to reconnect after a failed master event read' &&
+                               $row->State != 'Reconnecting after a failed master event read' &&
+                               $row->State != 'Registering slave on master'
+                               ) {
+                               # This is it, return the time (except -ve)
+                               if ( $row->Time > 0x7fffffff ) {
+                                       return false;
+                               } else {
+                                       return $row->Time;
+                               }
+                       }
+               }
+               return false;
+       }
+
        function getServerVersion() {
                return mysql_get_server_info( $this->mConn );
        }
index 9bb947f..9eb9e79 100644 (file)
@@ -1148,17 +1148,6 @@ class DatabaseOracle extends DatabaseBase {
                return 'BITOR(' . $fieldLeft . ', ' . $fieldRight . ')';
        }
 
-       /**
-        * How lagged is this slave?
-        *
-        * @return int
-        */
-       public function getLag() {
-               # Not implemented for Oracle
-               return 0;
-       }
-
-       function setFakeSlaveLag( $lag ) { }
        function setFakeMaster( $enabled = true ) { }
 
        function getDBname() {
index 784845d..578f12f 100644 (file)
@@ -1451,16 +1451,6 @@ SQL;
                return array( $startOpts, $useIndex, $preLimitTail, $postLimitTail );
        }
 
-       /**
-        * How lagged is this slave?
-        *
-        */
-       public function getLag() {
-               # Not implemented for PostgreSQL
-               return false;
-       }
-
-       function setFakeSlaveLag( $lag ) {}
        function setFakeMaster( $enabled = true ) {}
 
        function getDBname() {
index 418dcd0..535b5c4 100644 (file)
@@ -508,13 +508,6 @@ class DatabaseSqlite extends DatabaseBase {
                return parent::buildLike( $params ) . "ESCAPE '\' ";
        }
 
-       /**
-        * How lagged is this slave?
-        */
-       public function getLag() {
-               return 0;
-       }
-
        /**
         * Called by the installer script (when modified according to the MediaWikiLite installation instructions)
         * - this is the same way PostgreSQL works, MySQL reads in tables.sql and interwiki.sql using dbsource (which calls db->sourceFile)